package com.szyportal.web.front.controller;

import com.szyportal.common.core.controller.BaseController;
import com.szyportal.custom.domain.WAbout;
import com.szyportal.custom.domain.WConfig;
import com.szyportal.custom.domain.WNotice;
import com.szyportal.custom.domain.WPartner;
import com.szyportal.custom.service.IWAboutService;
import com.szyportal.custom.service.IWConfigService;
import com.szyportal.custom.service.IWNoticeService;
import com.szyportal.custom.service.IWPartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;

@Controller
public class PartnerController extends BaseController {

    @Autowired
    private IWPartnerService wPartnerService;
    @Autowired
    private IWConfigService wConfigService;
    @Autowired
    private IWAboutService aboutService;
    @Autowired
    private IWNoticeService wNoticeService;

    @GetMapping("/partner.html")
    public String partner(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
        // 广播
        List<WNotice> wNotices = wNoticeService.selectWNoticeList(null);
        model.put("notices", wNotices);
        String allNoticeContent = wNotices.stream()
                .map(WNotice::getContent)
                .collect(Collectors.joining("  "));
        model.put("allNoticeContent", allNoticeContent);
        List<WPartner> wPartners = wPartnerService.selectWPartnerList(null);
        model.put("wPartners",wPartners);
        WAbout wAbout = aboutService.selectWAboutById(2l);
        model.addAttribute("wAbout", wAbout);
        WConfig wConfig = wConfigService.selectWConfigById(1l);
        model.put("wConfig",wConfig);
        return "front/partner";
    }

//    // 查看详情
//    @GetMapping("/service/details")
//    public String details(HttpServletRequest request, @RequestParam("serviceId") String serviceId, HttpServletResponse response, ModelMap model) {
//        WServices wServices = wServicesService.selectWServicesById(Long.parseLong(serviceId));
//        WServices prewService = wServicesService.selectWServicesById(wServices.getPrewId());
//        WServices nextService = wServicesService.selectWServicesById(wServices.getNextId());
//        WConfig wConfig = wConfigService.selectWConfigById(1l);
//        model.put("wConfig",wConfig);
//        model.put("service", wServices);
//        model.put("prewService", prewService);
//        model.put("nextService", nextService);
//        return "front/service_details";
//    }
}
